import Actions from './Actions'
import Constants from '../constants/Constants'
import Dispatcher from '../Dispatcher'

const ActionTypes = Constants.ActionTypes

class UserActions extends Actions {
  login (data) {
    return this.ajax({
      type: 'POST',
      url: '/api/auth/login',
      data: {
        userName: data.name,
        password: data.pwd
      }
    }).done(resp => {
      if (resp && 0 === resp.code) {
        Dispatcher.dispatch({
          type: ActionTypes.LOGIN,
          data: resp
        })
        window.location.href = 'index.html'
      }
    })
  }

  check () {}
}

export default UserActions

